#ifndef TCPCI_PD_CONFIG_H
#define TCPCI_PD_CONFIG_H

/* Experimental for CodeSize */
#define CONFIG_USB_PD_DR_SWAP                       1
#define CONFIG_USB_PD_PR_SWAP                       1
#define CONFIG_USB_PD_VCONN_SWAP                    1
#define CONFIG_USB_PD_PE_SINK                       1
#define CONFIG_USB_PD_PE_SOURCE                     1
#define CONFIG_USB_PD_DISABLE_PE                    0 // of no use

#define CONFIG_USB_PD_TCPM_CB_RETRY                 3
#define CONFIG_USB_PD_TCPM_CB_2ND                   1
#define CONFIG_USB_PD_BLOCK_TCPM                    0 // only usable in rtos

/**********************************************************
 * PD revision 3.0 feature
 **********************************************************/

#define CONFIG_USB_PD_REV30                         1

#ifdef CONFIG_USB_PD_REV30
#include "tcpci_pd30_config.h"
#else /* CONFIG_USB_PD_REV30 = 0 */
#define CONFIG_USB_PD_REV30_SYNC_SPEC_REV           0
#define CONFIG_USB_PD_REV30_SRC_FLOW_DELAY_STARTUP  0
#define CONFIG_USB_PD_REV30_SNK_FLOW_DELAY_STARTUP  0
#define CONFIG_USB_PD_REV30_SRC_CAP_EXT_LOCAL       0
#define CONFIG_USB_PD_REV30_SRC_CAP_EXT_REMOTE      0
#define CONFIG_USB_PD_REV30_BAT_CAP_LOCAL           0
#define CONFIG_USB_PD_REV30_BAT_CAP_REMOTE          0
#define CONFIG_USB_PD_REV30_BAT_STATUS_LOCAL        0
#define CONFIG_USB_PD_REV30_BAT_STATUS_REMOTE       0
#define CONFIG_USB_PD_REV30_MFRS_INFO_LOCAL         0
#define CONFIG_USB_PD_REV30_MFRS_INFO_REMOTE        0
#define CONFIG_USB_PD_REV30_COUNTRY_CODE_LOCAL      0
#define CONFIG_USB_PD_REV30_COUNTRY_CODE_REMOTE     0
#define CONFIG_USB_PD_REV30_COUNTRY_INFO_LOCAL      0
#define CONFIG_USB_PD_REV30_COUNTRY_INFO_REMOTE     0
#define CONFIG_USB_PD_REV30_ALERT_LOCAL             0
#define CONFIG_USB_PD_REV30_ALERT_REMOTE            0
#define CONFIG_USB_PD_REV30_STATUS_LOCAL            0
#define CONFIG_USB_PD_REV30_STATUS_REMOTE           0
#define CONFIG_USB_PD_REV30_CHUNKING_BY_PE          0
#define CONFIG_USB_PD_REV30_PPS_SINK                0
#define CONFIG_USB_PD_REV30_PPS_SOURCE              0
#define CONFIG_USB_PD_REV30_STATUS_LOCAL_TEMP       0
#define CONFIG_USB_PD_REV30_BAT_INFO                0
#define CONFIG_USB_PD_REV30_COUNTRY_AUTHORITY       0
#define CONFIG_USB_PD_DPM_AUTO_SEND_ALERT           0
#define CONFIG_USB_PD_DPM_AUTO_GET_STATUS           0
#define CONFIG_MTK_HANDLE_PPS_TIMEOUT               0
#endif	/* CONFIG_USB_PD_REV30 */

/**********************************************************
 * PD direct charge support
 **********************************************************/
#define CONFIG_USB_PD_DIRECT_CHARGE                 0
#if CONFIG_USB_PD_REV30_PPS_SINK
#undef CONFIG_USB_PD_DIRECT_CHARGE
#define CONFIG_USB_PD_DIRECT_CHARGE                 0
#endif	/* CONFIG_USB_PD_REV30_PPS_SINK */

#define CONFIG_USB_PD_KEEP_PARTNER_ID               0
#define CONFIG_USB_PD_KEEP_SVIDS                    0

/**********************************************************
 *          Cable Discover Identify                       *
 **********************************************************/
#define CONFIG_USB_PD_SRC_STARTUP_DISCOVER_ID       1
#define CONFIG_USB_PD_DFP_READY_DISCOVER_ID         0
#if CONFIG_USB_PD_SRC_STARTUP_DISCOVER_ID || CONFIG_USB_PD_DFP_READY_DISCOVER_ID
#define CONFIG_PD_DISCOVER_CABLE_ID                 1
#else
#define CONFIG_PD_DISCOVER_CABLE_ID                 0
#endif

#define CONFIG_USB_PD_RESET_CABLE                   1
#if CONFIG_USB_PD_RESET_CABLE
#if CONFIG_USB_PD_SRC_STARTUP_DISCOVER_ID
#define CONFIG_PD_SRC_RESET_CABLE                   1
#else
#define CONFIG_PD_SRC_RESET_CABLE                   0
#endif
#if CONFIG_USB_PD_DFP_READY_DISCOVER_ID
#define CONFIG_PD_DFP_RESET_CABLE                   1
#else
#define CONFIG_PD_DFP_RESET_CABLE                   0
#endif
#endif // CONFIG_USB_PD_RESET_CABLE

#define CONFIG_PD_ALT_MODE_SUPPORT                  0
#define CONFIG_MAX_SVID_SUPPORT                     1
/**********************************************************
 *                DPM Flow Delay                          *
 **********************************************************/
#define CONFIG_USB_PD_RANDOM_FLOW_DELAY             0 // not supported in mcu

#define CONFIG_USB_PD_DFP_FLOW_DELAY                1
#ifdef CONFIG_USB_PD_DFP_FLOW_DELAY
#define CONFIG_USB_PD_DFP_FLOW_DELAY_STARTUP        1 // startup
#define CONFIG_USB_PD_DFP_FLOW_DELAY_DRSWAP         1 // after dr_swap
#define CONFIG_USB_PD_DFP_FLOW_DELAY_RESET          1 // after pe reset
#endif

#define CONFIG_USB_PD_UFP_FLOW_DELAY                1 // only in startup

#define CONFIG_USB_PD_VCONN_STABLE_DELAY            1 // dynamic vconn on -> vconn on
#define CONFIG_USB_PD_VCONN_SAFE5V_ONLY             0 // only support vconn on VBus vsafe5V

#define CONFIG_USB_PD_DISCARD_AND_UNEXPECT_MSG      1

#define CONFIG_USB_PD_ATTEMPT_DISCOVER_ID           1
#define CONFIG_USB_PD_ATTEMPT_DISCOVER_SVIDS        1

#if CONFIG_USB_PD_DFP_READY_DISCOVER_ID
#define CONFIG_USB_PD_DISCOVER_CABLE_REQUEST_VCONN  1 // request vconn src to discover cable
#define CONFIG_USB_PD_DISCOVER_CABLE_RETURN_VCONN   1 // return vconn src role to port partner after vconn src request
#else
#define CONFIG_USB_PD_DISCOVER_CABLE_REQUEST_VCONN  0
#define CONFIG_USB_PD_DISCOVER_CABLE_RETURN_VCONN   0
#endif

#define CONFIG_USB_PD_PR_SWAP_ERROR_RECOVERY        1 // transmit to error_recovery in PRS protocol error

#if CONFIG_TYPEC_CAP_DBGACC_SNK
#define CONFIG_USB_PD_CUSTOM_DBGACC                 1
#else
#define CONFIG_USB_PD_CUSTOM_DBGACC                 0 // default
#endif	/* CONFIG_TYPEC_CAP_DBGACC_SNK */

/**********************************************************
 *                   SW Patch                             *
 **********************************************************/
/* S/W patch for ESD issue: repeat HReset Alert */
#define CONFIG_USB_PD_RECV_HRESET_COUNTER           0 // transmit to error_recovery receiving 3 HRst

/* S/W patch for NoGoodCRC if SNK_DFT */
#define CONFIG_USB_PD_SNK_DFT_NO_GOOD_CRC           0 // of no use

/* S/W patch for NoGoodCRC after PR_SWAP (repeat PS_RDY) */
#define CONFIG_USB_PD_IGNORE_PS_RDY_AFTER_PR_SWAP   0 // of no use

/*
 * S/W patch for INT handler was stuck by other task (system busy)
 *
 * If the communication fails due to a timeout,
 * check the rx buffer is empty or not.
 *
 * If the rx buffer isn't empty, postpone timer.
 */

#define CONFIG_USB_PD_CHECK_RX_PENDING_IF_SRTOUT    0 // of no use

/*
 * S/W patch for
 * If the CC pin is shorted to ground and our receive ability is better,
 * then we may receive message however always send failed.
 *
 * For the source role, it becomes an infinite hard reset loop.
 * For the sink role, it becomes an infinite error recovery loop.
 *
 * RENEGOTIATION_COUNTER:
 *     Auto error recovery
 *     if retried hard reset many times still negotiation failed.
 *
 * ERROR_RECOVERY_ONCE:
 *     If we have tried an error recovery,
 *     using pure typec mode during next time we reconnect.
 *
 */
#define CONFIG_USB_PD_RENEGOTIATION_COUNTER         1 // limit hard_reset times
#define CONFIG_USB_PD_ERROR_RECOVERY_ONCE           1 // limit error_recovery times

#define CONFIG_USB_PD_IGNORE_HRESET_COMPLETE_TIMER  0 // deprecated
#define CONFIG_USB_PD_RETRY_HRESET                  1
#define CONFIG_USB_PD_DROP_REPEAT_PING              1
#define CONFIG_USB_PD_CHECK_DATA_ROLE               1 // check data role of received msg
#define CONFIG_USB_PD_RETRY_CRC_DISCARD             1 // retry if tx discard for receiving GoodCRC
#define CONFIG_USB_PD_PARTNER_CTRL_MSG_FIRST        1 // return to READY if port partner sending CTRL

#define CONFIG_USB_PD_SNK_IGNORE_HRESET_IF_TYPEC_ONLY    0
#define CONFIG_USB_PD_SNK_STANDBY_POWER             1 // Sink Standby, TODO
#define CONFIG_USB_PD_SNK_GOTOMIN                   0 // deprecated

#define CONFIG_USB_PD_SRC_HIGHCAP_POWER             0 // need discharge if highcap
#define CONFIG_USB_PD_SRC_TRY_PR_SWAP_IF_BAD_PW     1 // request PRS as sink if remote uncontrained power
#define CONFIG_USB_PD_SRC_REJECT_PR_SWAP_IF_GOOD_PW 0 // reject PRS as src if local uncontrained power

#define CONFIG_USB_PD_TRANSMIT_BIST2                1


/**********************************************************
 *                SW Delay Mechanism                      *
 **********************************************************/
#ifndef CONFIG_USB_PD_SAFE0V_DELAY
#define CONFIG_USB_PD_SAFE0V_DELAY                  200 // postpone vsafe0v event
#endif
#ifndef CONFIG_USB_PD_SAFE0V_TIMEOUT
#define CONFIG_USB_PD_SAFE0V_TIMEOUT                600 // force discharge and wait vsafe0v
#endif
#ifndef CONFIG_USB_PD_SAFE5V_DELAY
#define CONFIG_USB_PD_SAFE5V_DELAY                  20 // postpone vbus changed event
#endif
#ifndef CONFIG_USB_PD_DPM_SVDM_RETRY
#define CONFIG_USB_PD_DPM_SVDM_RETRY                2
#endif
#ifndef CONFIG_USB_PD_DFP_FLOW_RETRY_MAX
#define CONFIG_USB_PD_DFP_FLOW_RETRY_MAX            2 // of no use
#endif
#ifndef CONFIG_USB_PD_VBUS_STABLE_TOUT
#define CONFIG_USB_PD_VBUS_STABLE_TOUT              125 // wait time of src power stable
#endif
#ifndef CONFIG_USB_PD_CUSTOM_VDM_TOUT
#define CONFIG_USB_PD_CUSTOM_VDM_TOUT               500 // of no use
#endif
#ifndef CONFIG_USB_PD_VCONN_READY_TOUT
#define CONFIG_USB_PD_VCONN_READY_TOUT              5 // wait time of vconn stable
#endif
#ifndef CONFIG_USB_PD_DFP_FLOW_DLY
#define CONFIG_USB_PD_DFP_FLOW_DLY                  50 // CONFIG_USB_PD_DFP_FLOW_DELAY
#endif
#ifndef CONFIG_USB_PD_UFP_FLOW_DLY
#define CONFIG_USB_PD_UFP_FLOW_DLY                  300 // CONFIG_USB_PD_UFP_FLOW_DELAY
#endif
#ifndef CONFIG_USB_PD_PPS_REQUEST_INTERVAL
#define CONFIG_USB_PD_PPS_REQUEST_INTERVAL          7000 // shall less than 10000 ms
#endif

#define CONFIG_USB_PD_WAIT_BC12                     0 // of no use

#endif /* TCPCI_PD_CONFIG_H */

